package customerService

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/customerservicegroup"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/rpc"
	"github.com/zeromicro/go-zero/core/logc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateCustomerServiceStatusLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 修改客服管理状态
func NewUpdateCustomerServiceStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCustomerServiceStatusLogic {
	return &UpdateCustomerServiceStatusLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateCustomerServiceStatusLogic) UpdateCustomerServiceStatus(req *types.UpdateCustomerServiceStatusReq) (resp *types.Empty, err error) {
	if req.Id == 0 {
		return nil, code.ParamsInvalid
	}

	u, err := l.svcCtx.SettingService.CustomerService.UpdateCustomerServiceStatus(l.ctx, &customerservicegroup.UpdateCustomerServiceStatusReq{
		MerchantId: 1,                          // 商户ID
		Id:         req.Id,                     // id
		Status:     rpc.StatusType(req.Status), // 状态,0:关闭,1:启用
	})

	if err != nil {
		logc.Error(l.ctx, "UpdateCustomerServiceStatus err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}

	resp = &types.Empty{}
	return
}
